//
//  BuyPackageViewController.m
//  Manage
//
//  Created by 杨康 on 2018/1/11.
//  Copyright © 2018年 杨康. All rights reserved.
//

#import "BuyPackageViewController.h"

@interface BuyPackageViewController ()
{
    UIButton *_selectButton;
    NSInteger type;
}
@end

@implementation BuyPackageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title=@"购买套餐";
    
    type=0;
    
    
    UILabel *chooseLab=[SingLeton myLabel:[UIColor color6] andTitle:@"选择套餐" andFont:14];
    [self.view addSubview:chooseLab];
    [chooseLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(TOP_HEIGHT+20);
    }];
    
    
    
    YKButton *toBuyButton=[SingLeton endButton:[UIColor colorWithHexString:@"09be00"] andTitle:@"交纳押金" RequestSuccess:^(UIButton *btn) {
        
    }];
    [self.view addSubview:toBuyButton];
    [toBuyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(chooseLab);
        make.size.mas_equalTo(CGSizeMake(60, 22));
    }];
    toBuyButton.titleLabel.font=[UIFont systemFontOfSize:12];
    toBuyButton.layer.cornerRadius=3;
    
    
    UILabel *tobuyLab=[SingLeton myLabel:[UIColor colorWithHexString:@"222222"] andTitle:@"交纳押金更实惠" andFont:14];
    [self.view addSubview:tobuyLab];
    [tobuyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(chooseLab);
        make.right.mas_equalTo(toBuyButton.mas_left).mas_offset(-5);
    }];
    
    
    
    
    
    
    
    
    
    
    UIImageView *bgImg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"套餐背景"]];
    [self.view addSubview:bgImg];
    [bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-30, (SCREEN_WIDTH-30)*8/23));
        make.top.mas_equalTo(chooseLab.mas_bottom).mas_offset(15);
    }];
    
    
    UILabel *typeLab=[[UILabel alloc]init];
    [bgImg addSubview:typeLab];
    [typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.mas_equalTo(10);
        
    }];
    
    typeLab.font=[UIFont boldSystemFontOfSize:17];
    typeLab.textColor=[UIColor colorWithHexString:@"09be00"];
    
    
    
    
    UILabel *tipLab=[SingLeton myLabel:[UIColor colorWithHexString:@"222222"] andTitle:@"不限次/月" andFont:14];
    [bgImg addSubview:tipLab];
    [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(typeLab.mas_bottom).mas_offset(10);
    }];
    
    
    UILabel *noVipLab=[SingLeton myLabel:[UIColor colorWithHexString:@"222222"] andTitle:@"无押金价：210元" andFont:10];
    [bgImg addSubview:noVipLab];
    [noVipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.bottom.mas_equalTo(-8);
    }];
    
    
    UILabel *vipLab=[SingLeton myLabel:[UIColor colorWithHexString:@"09be00"] andTitle:@"150元" andFont:16];
    [bgImg addSubview:vipLab];
    [vipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.bottom.mas_equalTo(noVipLab.mas_top).mas_offset(-5);
    }];
    
    
    
    
    
    
    UILabel *listLab=[SingLeton myLabel:[UIColor color6] andTitle:@"支付方式" andFont:14];
    [self.view addSubview:listLab];
    [listLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(bgImg.mas_bottom).mas_offset(30);
    }];
    
    
    
    UIImageView *YEImg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"余额"]];
    [self.view addSubview:YEImg];
    [YEImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(listLab.mas_bottom).mas_offset(20);
    }];
    
    UILabel *YELab=[[UILabel alloc]init];
    [self.view addSubview:YELab];
    [YELab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(YEImg);
        make.left.mas_equalTo(YEImg.mas_right).mas_offset(10);
    }];
    
    
    
    
    
    
    
    UIButton *YEButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:YEButton];
    [YEButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(YEImg);
        make.right.mas_equalTo(-30);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    
    [YEButton setImage:[UIImage imageNamed:@"可选"] forState:UIControlStateNormal];
    [YEButton setImage:[UIImage imageNamed:@"选择"] forState:UIControlStateSelected];
    [YEButton setImage:[UIImage imageNamed:@"不可选"] forState:UIControlStateDisabled];
    YEButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [YEButton addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    
    
    
    
    UIImageView *zfbImg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"支付宝"]];
    [self.view addSubview:zfbImg];
    [zfbImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(YEImg.mas_bottom).mas_offset(20);
        
    }];
    
    UILabel *zfbLab=[SingLeton myLabel:[UIColor color3] andTitle:@"支付宝" andFont:17];
    [self.view addSubview:zfbLab];
    [zfbLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(zfbImg);
        make.left.mas_equalTo(zfbImg.mas_right).mas_offset(10);
    }];
    
    
    UIButton *zfbButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:zfbButton];
    [zfbButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(zfbImg);
        make.right.mas_equalTo(-30);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    
    [zfbButton setImage:[UIImage imageNamed:@"可选"] forState:UIControlStateNormal];
    [zfbButton setImage:[UIImage imageNamed:@"选择"] forState:UIControlStateSelected];
    zfbButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [zfbButton addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside];
    [self payAction:zfbButton];
    
    UIImageView *wxImg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"微信支付"]];
    [self.view addSubview:wxImg];
    [wxImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(zfbImg.mas_bottom).mas_offset(20);
    }];
    
    UILabel *wxLab=[SingLeton myLabel:[UIColor color3] andTitle:@"微信支付" andFont:17];
    [self.view addSubview:wxLab];
    [wxLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(wxImg);
        make.left.mas_equalTo(wxImg.mas_right).mas_offset(10);
    }];
    
    
    UIButton *wxButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:wxButton];
    [wxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(wxImg);
        make.right.mas_equalTo(-30);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    
    [wxButton setImage:[UIImage imageNamed:@"可选"] forState:UIControlStateNormal];
    [wxButton setImage:[UIImage imageNamed:@"选择"] forState:UIControlStateSelected];
    wxButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [wxButton addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *payButton=[SingLeton endButton:[UIColor colorWithHexString:@"09be00"] andTitle:@"确认支付" RequestSuccess:^(UIButton *btn) {
        
    }];
    [self.view addSubview:payButton];
    [payButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.bottom.mas_equalTo(-20);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-40, 44));
    }];
    
    
    
    if (type==0) {
        tobuyLab.hidden=NO;
        toBuyButton.hidden=NO;
        typeLab.text=@"按月套餐(无押金)";
        vipLab.text=@"210元";
        noVipLab.text=@"有押金价：150元";
        
        
        YEButton.enabled=YES;
        
        NSString *str0=@"余额";
        NSString *str1=@"";
        
        YELab.attributedText=[NetworkPath setRichText:str0 withFont:17 withColor:[UIColor colorWithHexString:@"222222"] andOtherText:str1 withFont:17 withColor:[UIColor color9] atIndex:2];
        
        
    }else
    {
        tobuyLab.hidden=YES;
        toBuyButton.hidden=YES;
        typeLab.text=@"按月套餐(有押金)";
        vipLab.text=@"150元";
        noVipLab.text=@"无押金价：210元";
        
        YEButton.enabled=NO;
    
        NSString *str0=@"余额";
        NSString *str1=@"(余额不足)";
        
        YELab.attributedText=[NetworkPath setRichText:str0 withFont:17 withColor:[UIColor colorWithHexString:@"222222"] andOtherText:str1 withFont:17 withColor:[UIColor color9] atIndex:2];
    }
    
}

-(void)payAction:(UIButton *)btn
{
    
    if (_selectButton) {
        _selectButton.selected=NO;
    }
    
    _selectButton=btn;
    btn.selected=YES;
}
@end
